export default class Message {
    constructor( type ){
        this.data = {};
        this.type = type;
    }
    get type(){
        return this.data["type"];
    }
    set type( type ) {
        this.data["type"] = type;
    }
    static createFromJson( jsonStr ) {
        let msg = new Message( Message.Type.Unknow );
        try {
            let data = JSON.parse( jsonStr );
            Object.assign( msg.data, data );
        }catch( e ){
            console.log( "Message::createFromJson, error", jsonStr, e );
        }
        return msg;
    }
    toJSON(){
        return this.data;
    }
}

Message.Type = {
    Unknow :            0,
    CMLoginGuest :      1,
    CMLogout :          2,
    CMUserIn :          3,
    CMUserOut :         4,
    CMAddBubble :       5,
    MCWelcome :         6,
    MCLoginGuest :      7,
    MCLogout:           8,
    MCUserIn :          9,
    MCRoomInfo:         10,
    MCUserOut :         11,
    MCAddBubble :       12,
    MCArriveBubble :    13,
    MCError :           14,
};